<h1 class="right">تقرير حركة الموظفين</h1>
<div class="clear"></div>

<div id="dashboard-container">
	<div class="customers-filter">
    	<form name="contract_search" action="" method="POST" id="searchClient">
      <table class="bookings-filter" >
        	
          <tr>
            <td width="10">من  </td>
                <td>
                  <input type="text" class="small-input" name="from" id="from-0" placeholder=""  value="<?php if(isset($binds['from']) ) {echo $binds['from'];} ?>"/>
                </td>
                <td>الى</td>
                <td><input type="text" class="small-input" name="to" id="to-0" placeholder="" value="<?php if(isset($binds['to']) ) {echo $binds['to'];} ?>" /></td>
            	<td style="width:90px;">اسم الموظف:  </td>
                <td style="width:100px;">
                  <input type="text" class="small-input" name="name" id="" placeholder=""  value="<?php if(isset($binds['name']) ) {echo $binds['name'];} ?>"/>
                </td>
                
                <input type="hidden" id="page" name="page" value="" />
				
               <td></td><td></td><td></td>
                <td style="width:50px">
                  <input type="hidden" name="filteration" value="3"/> <!-- 1 for reciept Reposts -->
                  <a href="#"><div class="export-button">تصدير Excel</div></a>
                  
                  <input type="hidden" id="pdf_excel" name="pdf_excel" value="0"/>
                </td>
                <td style="width:50px"><a href="#"><div class="export-PDF">تصدير PDF</div></a></td>

                <td style="width:50px"><div class="search-botton">بحث</div></td>
                
            </tr>
            
      </table>
      </form>
    </div>
    
    
    <div class="dashboard-row">
    
    	<table class="customers-table">
        	<thead>
            <tr class="customers-table-head">
            	<td width="">اسم الموظف</td>
              <td width="">عدد العقود</td>
              <td width="">عدد سندات الصرف</td>
              <td width="">اجمالى سندات الصرف</td>
			   <td width="">عدد سندات القبض</td>
			  <td width="">اجمالى سندات القبض </td>
              <td width="">المبلغ الصافى</td>
              <!--<td width="">العمليات</td> -->
              
              
            </tr>
            </thead>
            
            <?php foreach($employees as $employee) {?>
                <tr class="">
                    <td width=""><?php echo $employee['first_name']." ".$employee['last_name']; ?></td>
					<?php
					
					if(!empty($_POST['from']) && !empty($_POST['to'])){
					$contract_num= query('SELECT  COUNT(*) FROM contracts  WHERE user_id=? AND created_at between ? AND ?',$employee['user_id'],$_POST['from'],$_POST['to']);
					?>
					 <td class="blue" width=""><?php echo $contract_num[0]['COUNT(*)']; ?></td>
				 <?php
					}else{
					$contract_num= query("SELECT COUNT(*) FROM contracts WHERE user_id=? ",$employee['user_id']); 
					?>
                    <td class="blue" width=""><?php echo $contract_num[0]['COUNT(*)']; ?></td>
					<?php 
					}
					if(!empty($_POST['from']) && !empty($_POST['to'])){
					$payments_num= query('SELECT COUNT(*) FROM payment_vouchers WHERE user_id=? AND miladi_date between ? AND ?',$employee['user_id'],$_POST['from'],$_POST['to']);
					?>
					 <td class="blue" width=""><?php echo $payments_num[0]['COUNT(*)']; ?></td>
					<?php
					}else{
					$payments_num= query('SELECT COUNT(*) FROM payment_vouchers WHERE user_id=?',$employee['user_id']);
					?>
                    <td class="blue" width=""><?php echo $payments_num[0]['COUNT(*)']; ?></td>
					<?php
					}
					if(!empty($_POST['from']) && !empty($_POST['to'])){
					$payments_sum= query('SELECT SUM(amount) FROM payment_vouchers WHERE user_id=? AND miladi_date between ? AND ?',$employee['user_id'],$_POST['from'],$_POST['to']);
                   ?>
				   <td width=""><?php echo $payments_sum[0]['SUM(amount)']; ?></td>
				   <?php
				   }else {
					$payments_sum= query('SELECT SUM(amount) FROM payment_vouchers WHERE user_id=?',$employee['user_id']);
					?>
                    <td width=""><?php echo $payments_sum[0]['SUM(amount)']; ?></td>
					<?php
					}
					if(!empty($_POST['from']) && !empty($_POST['to'])){
					$reciept_num= query('SELECT COUNT(*) FROM recipt_vouchers WHERE user_id=? AND miladi_date between ? AND ? ',$employee['user_id'],$_POST['from'],$_POST['to']); 
					?>
					<td width=""><?php echo $reciept_num[0]['COUNT(*)']; ?></td>
					<?php
					}else{
					$reciept_num= query('SELECT COUNT(*) FROM recipt_vouchers WHERE user_id=?',$employee['user_id']);
					?>
                    <td width=""><?php echo $reciept_num[0]['COUNT(*)']; ?></td>
					<?php
					}
					if(!empty($_POST['from']) && !empty($_POST['to'])){
					$reciept_sum= query('SELECT SUM(amount) FROM recipt_vouchers WHERE user_id=? AND miladi_date between ? AND ?',$employee['user_id'],$_POST['from'],$_POST['to']); 
					?>
					<td width=""><?php echo $reciept_sum[0]['SUM(amount)']; ?></td>
					<?php
					}else{
					$reciept_sum= query('SELECT SUM(amount) FROM recipt_vouchers WHERE user_id=?',$employee['user_id']); 
					?>
                    <td width=""><?php echo $reciept_sum[0]['SUM(amount)']; ?></td>
					<?php
					}
					$all= $reciept_sum[0]['SUM(amount)']+ $payments_sum[0]['SUM(amount)'] ; ?>
                    <td class="" width=""> <?php  echo $all; ?> </td>
                <!--    <td class="" width="">                       <!-- View pop-up triggerer, Ajax request will be sent to href url 
                      <a href="view-pop-ups/employeedetails.php" class="ajax-pop-ups-magnific-no-modal"><img src="images/view.png" class="" align="" title="تفاصيل السندات"alt="View"/></a>
</td>  -->
             
                </tr>
             
            <?php }  ?>
        </table><br />
        <hr />
        <?php
          $start = $page * 20 -19;
          $end  = $start + 19;
          if($end > $totalPages)
            $end = $totalPages;
          
        ?>
        <?php if(!empty($employees)) { ?>
        <div class="clear"></div>
        <div class="relative">
          <div id="employee-selection" class="center"></div>
          <span class="middle xsmall showing-results absolute">عرض النتائج <?php echo $start; ?> - <?php echo $end; ?> من إجمالى <?php echo $totalPages; ?></span>
        </div> 

        <div class="hidden totalPages"><?php if(isset($totalPages)) {echo $totalPages;} ?></div>
        <div class="hidden currentPage"><?php if(isset($page)) {echo $page;} ?></div>
        <?php } ?>
    </div>
    <hr />
    
  <div class="clear"></div>
  </div>
</div>        
